import React from 'react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import { ConfigProvider } from 'antd';
import zhCN from 'antd/locale/zh_CN';
import Layout from './components/Layout/Layout';
import Dashboard from './pages/Dashboard/Dashboard';
// import ManualSqlAnalysis from './pages/ManualSqlAnalysis/ManualSqlAnalysis';  // 暂时屏蔽
import CreateTask from './pages/CreateTask/CreateTask';
import TaskList from './pages/TaskList/TaskList';
import TaskDetail from './pages/TaskDetail/TaskDetail';
import Rules from './pages/Rules/Rules';
import Login from './pages/Login/Login';
import ProtectedRoute from './components/ProtectedRoute/ProtectedRoute';
import './App.css';

// 开发环境下导入WebSocket测试工具
if (process.env.NODE_ENV === 'development') {
  import('./utils/websocketDevTest').then((module) => {
    console.log('🔧 开发环境: WebSocket测试工具已加载');
    console.log('💡 在浏览器控制台运行 testWebSocketConnection() 来测试WebSocket连接');
  });
}

const App: React.FC = () => {
  return (
    <ConfigProvider locale={zhCN}>
      <Router>
        <Routes>
          {/* 登录路由 - 不需要Layout包装 */}
          <Route path="/login" element={<Login />} />
          
          {/* 公开访问的任务详情页面 - 不需要登录 */}
          <Route path="/tasks/public/:id" element={
            <Layout>
              <TaskDetail isPublicAccess={true} />
            </Layout>
          } />
          
          {/* 受保护的路由 - 需要登录后才能访问 */}
          <Route path="/*" element={
            <ProtectedRoute>
              <Layout>
                <Routes>
                  <Route path="/" element={<Dashboard />} />
                  <Route path="/dashboard" element={<Dashboard />} />
                  
                  {/* 统一的SQL在线分析页面 - 暂时屏蔽 */}
                  {/* <Route path="/manual-sql-analysis" element={<ManualSqlAnalysis />} /> */}
                  
                  <Route path="/create-task" element={<CreateTask />} />
                  <Route path="/tasks" element={<TaskList />} />
                  <Route path="/tasks/:id" element={<TaskDetail isPublicAccess={false} />} />
                  <Route path="/history" element={<TaskList />} />
                  <Route path="/rules" element={<Rules />} />
                </Routes>
              </Layout>
            </ProtectedRoute>
          } />
        </Routes>
      </Router>
    </ConfigProvider>
  );
};

export default App;